from Libs import MysqlModel


class HostPort():

    @staticmethod
    def select():
        MysqlApi = MysqlModel.mysql()
        data = MysqlApi.select("select * from host_port ")

        print(data)

    @staticmethod
    def insert(openPort):
        MysqlApi = MysqlModel.mysql()

        # SQL 插入语句

        sql = "INSERT INTO host_port(`host`,  `port`, `status`  " \
              "VALUES ('%s', '%s', '%s' )" % (openPort[0], openPort[1], openPort[2])

        MysqlApi.insert(sql)

    @staticmethod
    def insertMulti(openPortList):
        print(openPortList)
        MysqlApi = MysqlModel.mysql()

        # SQL 插入语句
        sql = "INSERT INTO host_port(`host`,  `port`, `status`)  VALUES "

        for openPort in openPortList:
            print(openPort)
            sql += "('%s', '%s', '%s' )," % (openPort[0], openPort[1], openPort[2])

        sql = sql.rstrip(",")
        print(sql)
        MysqlApi.insert(sql)

    @staticmethod
    def delete():
        MysqlApi = MysqlModel.mysql()

        # SQL 插入语句
        sql = "DELETE FROM host_port WHERE AGE = %s" % (20)

        MysqlApi.insert(sql)
